package com.xy.annotaion.handler.aop.advice.adapter;

import com.xy.annotaion.handler.aop.advice.TestAdvice;
import com.xy.annotaion.handler.util.Pointer;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.adapter.AdvisorAdapter;

/**
 * it will not be registered automatically!!!
 *
 * @author Dell
 */
//@Deprecated
//@Component
public class TestAdvisorAdapter implements AdvisorAdapter {
    @Override
    public boolean supportsAdvice(Advice advice) {
        return advice instanceof TestAdvice;
    }

    @Override
    public MethodInterceptor getInterceptor(Advisor advisor) {
        TestAdvice testAdvice = (TestAdvice) advisor.getAdvice();
        return new MethodInterceptor() {
            @Override
            public Object invoke(MethodInvocation invocation) throws Throwable {
                Pointer.lg("(2)");
                return testAdvice.invoke(invocation);
            }
        };
    }
}
